import turtle
import random
import time

# 发射烟花
def firework(t):
    t.hideturtle()
    t.pensize(2)
    t.speed(0)
    x = random.randint(-200, 200)
    y = random.randint(-200, 200)
    t.penup()
    t.goto(x, y)
    t.pendown()
    for i in range(36):
        t.forward(50)
        t.backward(50)
        t.right(10)
    t.penup()

# 绽放效果
def burst(t):
    colors = ["red", "orange", "yellow", "green", "blue", "purple"]
    t.speed(0)
    for i in range(30):
        t.pencolor(random.choice(colors))
        t.penup()
        t.goto(random.randint(-200, 200), random.randint(-200, 200))
        t.pendown()
        size = random.randint(10, 50)
        for j in range(6):
            t.forward(size)
            t.backward(size)
            t.right(60)


wn = turtle.Screen()
wn.bgcolor("black")
wn.title("Fireworks Simulation")

t = turtle.Turtle()

for _ in range(5):
    firework(t)
    burst(t)
    time.sleep(1)

wn.mainloop()

